System and method for supporting a lazy sorting priority queue in a computing environment

ABSTRACT

A system and method can support queue processing in a computing environment. A lazy sorting priority queue in a concurrent system can include a priority queue and one or more buffers. The one or more buffers, which can be first-in first-out (FIFO) buffers, operate to store one or more requests received from one or more producers, and move at least one message to the priority queue when no consumer is waiting for processing a request. Furthermore, the priority queue operates to prioritize one or more incoming requests received from the one or more buffers, and allows one or more consumers to pick up the requests based on priority.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is related to the following patent applications, each of which is hereby incorporated by reference in its entirety:

U.S. Patent Application titled “SYSTEM AND METHOD FOR SUPPORTING COOPERATIVE CONCURRENCY IN A MIDDLEWARE MACHINE ENVIRONMENT”, Application No. ______, filed _______, 2013 (Attorney Docket No. ORACL-05420US0);

U.S. Patent Application titled “SYSTEM AND METHOD FOR USING A SEQUENCER IN A CONCURRENT PRIORITY QUEUE”, Application No. _______, filed _______, 2013 (Attorney Docket No. ORACL-05420US1);

U.S. Patent Application titled “SYSTEM AND METHOD FOR TRANSFORMING A QUEUE FROM NON-BLOCKING TO BLOCKING”, Application No. _______, filed ______, 2013 (Attorney Docket No. ORACL-05420U52); and

U.S. Patent Application titled “MULTI-LANE CONCURRENT BAG FOR FACILITATING INTER-THREAD COMMUNICATION”, Application Ser. No. 13/241,015, filed Sep. 22, 2011.

COPYRIGHT NOTICE

A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.

FIELD OF INVENTION

The present invention is generally related to computer systems, and is particularly related to queue processing in a computing environment.

BACKGROUND

Within any large organization, over the span of many years, the organization often finds itself with a sprawling IT infrastructure that encompasses a variety of different computer hardware, operating systems, and application software. Although each individual component of such infrastructure might itself be well-engineered and well-maintained, when attempts are made to interconnect such components, or to share common resources, it is often a difficult administrative task. In recent years, organizations have turned their attention to technologies such as virtualization and centralized storage, and even more recently cloud computing, which can provide the basis for a shared infrastructure. However, there are few all-in-one platforms that are particularly suited for use in such environments. These are the general areas that embodiments of the invention are intended to address.

SUMMARY

Described herein are systems and methods that can support queue processing in a computing environment. A lazy sorting priority queue in a concurrent system can include a priority queue and one or more buffers. The one or more buffers, which can be first-in first-out (FIFO) buffers, operate to store one or more requests received from one or more producers, and move at least one message to the priority queue when no consumer is waiting for processing a request. Furthermore, the priority queue operates to prioritize one or more incoming requests received from the one or more buffers, and allows one or more consumers to pick up the requests based on priority.

BRIEF DESCRIPTION OF THE FIGURES

FIG. 1 shows an illustration of supporting efficient queue processing in a computing environment, in accordance with an embodiment of the invention.

FIG. 2 illustrates an exemplary flow chart for supporting queue processing in a computing environment, in accordance with an embodiment of the invention.

FIG. 3 shows an illustration of supporting concurrent thread operations in a lazy sorting priority queue, in accordance with an embodiment of the invention.

FIG. 4 shows an illustration of performing an enqueue operation by a producer in a computing environment, in accordance with an embodiment of the invention.

FIG. 5 shows an illustration of performing a dequeue operation by a consumer in a computing environment, in accordance with an embodiment of the invention.

FIG. 6 shows an illustration of performing an operation to move an element from a FIFO buffer to a priority queue, in accordance with an embodiment of the invention.

FIG. 7 shows an illustration of an exemplary lazy sorting priority queue, in accordance with an embodiment of the invention.

DETAILED DESCRIPTION

Described herein are systems and methods that can support queue processing in a computing environment.

Lazy Sorting Priority Queue

Priority queues can be used for prioritizing the elements in a concurrent system, which may be received in a total order, based on different application-specific criteria. For example, the priority queues can be used to prioritize service requests that are received at a messaging system, and to re-arrange these enqueued service requests into a different order.

Furthermore, the performance of the priority queue may contribute significantly toward the overall performance of the concurrent system, even though the priority queue can be designed and implemented using different approaches. For example, the prioritization of the enqueued elements within a priority queue may require a complete sorting of all the enqueued elements, which is an operation with at least O(log) complexity. Additionally, the system may need to use a complex data structure for maintaining the various requests in a prioritized order in a concurrent priority queue.

In accordance with an embodiment of the invention, the system can reduce the overhead (e.g. from sorting) by taking into account contention pressure from various consumers that are ready to dequeue the requests.

FIG. 1 shows an illustration of supporting efficient queue processing in a computing environment, in accordance with an embodiment of the invention. As shown in FIG. 1, the computing environment 100 includes a priority queue 101 and one or more buffers, such as one or more first-in first-out (FIFO) buffers 111-113 in a FIFO queue 102. Here, multiple FIFO buffers 111-113 can be arranged orthogonally in order to reduce the CPU cache contention.

In accordance with an embodiment of the invention, multiple producers 110 and multiple consumers 120 can access the priority queue 101 and the FIFO queue 102 concurrently. For example, the producers 110 can be muxer threads unmarshalling requests from network connections, and the consumers 120 can be worker threads picking up requests from the priority queue 101.

When the contention level is low in the system, the underlying priority queue 101 can sort the requests waiting in the priority queue 101 (with a logarithmic cost) in order to ensure that the request with the highest priority in the priority queue 101 can have the shortest waiting time. Thus, when the next consumer 120, or worker thread, is allowed to pick up a unit of work, it can pick up the unit with the highest priority. Here, the consumers 120, or the worker threads, may take arbitrary time to process the requests, and the requests in the priority queue 101 may be considered waiting only after the last consumer 102 leaves the dequeue entry point.

Additionally, the consumer 120 can retrieve a request from the priority queue 101 by calling a poll( )method. As shown in FIG. 1, the consumers 120 can use a ticketing system 104 and a consumer sequencer 105 in order to ensure that only one working thread is accessing the priority queue 101 at any given time. For example, the ticketing system 103 can be implemented using an atomic ticketing system.

Also, a producer 110 can place an element in the FIFO queue first. As shown in FIG. 1, the producers 110 can use a separate ticketing system 103, which can also be an atomic ticketing system, and employ one or more buffer sequencers, such as the FIFO buffer sequencers 121-123 for the FIFO buffers 111-113.

In accordance with an embodiment of the invention, the system allows the producer 110 to select a FIFO buffer from the FIFO queue 102. Furthermore, the system allows the request to be moved from a selected FIFO buffer 111-113 to the priority queue using a put( )method call.

Here, due to the need for sorting the elements in the priority queue 101, an operation based on ether the put( )method or the poll( )method may have a logarithmic cost. Thus, the system can reduce the cost for sorting the elements in a priority queue by reducing the number of calls to these methods under contention.

In order to improve the efficiency of the concurrent system, both the producer 110 and the consumer 120 may attempt to move one or more elements to the priority queue 101, when no consumer is waiting for processing a request in the priority queue 101 (i.e. when there is no contention).

On the other hand, when the contention level is high, i.e. when one or more consumers 120 are ready to extract units of work from the priority queue 101, the priority of the requests waiting in the priority queue 101 to be processed may be higher than the priority of the requests after they are picked up. Thus, the system allows the producers 110 to be blocked when attempting to add one or more elements to the priority queue 101, and allows the elements to remain unsorted in the FIFO queue 102, as long as there are consumers contending for the sequencer.

Subsequently, the units of work can be moved from the FIFO queue 102 to the priority queue 101, a later time when a future producer and/or a future consumer finds no contention, or until the units of work can be extracted by consumers 120 in the FIFO order, if the contention remains high.

FIG. 2 illustrates an exemplary flow chart for supporting queue processing in a computing environment, in accordance with an embodiment of the invention. As shown in FIG. 2, at step 201, the system can provide a priority queue, wherein the priority queue operates to prioritize one or more incoming requests. Furthermore, at step 202, the system can provide one or more buffers, wherein each said buffer operates to store one or more requests received from one or more producers. Additionally, at step 203, the system can move at least one message from said one or more buffers to the priority queue when no consumer is waiting for processing a request.

Concurrent Thread Operations

FIG. 3 shows an illustration of supporting concurrent thread operations in a lazy sorting priority queue, in accordance with an embodiment of the invention. As shown in FIG. 3, a lazy sorting priority queue 300, which is a concurrent system, can include a priority queue 301 and a FIFO buffer 302.

Furthermore, a producer 310 can place a request in the FIFO buffer 302. Then, the request can be moved to the priority queue 301 using a put( )method call. Additionally, a consumer 320 can place a poll( )method call to retrieve a request from the priority queue 301. In order to improve the efficiency of the concurrent system 300, each of the producer 310 and consumer 320 may attempt to move one or more elements from the FIFO buffer 302 to the priority queue 301, e.g. by calling an addLoop( )method.

As shown in FIG. 3, in order to guarantee a single-threaded access to the underlying priority queue 301, the ticketing system 312 and sequencer 311 can be used by both the producer 310 and the consumer 320 in calling the addLoop( )method. Additionally, the consumer 320 can use the same ticketing system 312 and sequencer 311 in calling the poll( )method.

In other words, the sequencer 311 permits a thread (either the producer 310 or the consumer 320) to have an exclusive access to the priority queue 201, when there are no threads calling the poll( )method and the addLoop( )method. Then, the thread can move one or more elements from the FIFO buffer 302 to the priority queue 301, e.g. using a priorityQueue.put( )method call.

In accordance with an embodiment of the invention, the system ensures that the elements (or units of work) can be moved lazily, or opportunistically, when there is no contention from the consumers 320. On the other hand, the consumers 320 can take precedence once they arrive, and the consumers 320 are allowed to extract elements from the FIFO buffer 302 without having all known requests sorted.

Thus, the concurrent system can behave similarly to a priority queue 301 with a lock biased towards the consumers 320. The system makes sure that the priority queue 301 is short and the cost of adding and removing elements from the priority queue 301 is minimized. For example, at high contention levels, the priority queue 301 becomes completely empty, while the requests in the concurrent system 300 may be processed in the FIFO order.

FIG. 4 shows an illustration of performing an enqueue operation 400 by a producer in a computing environment, in accordance with an embodiment of the invention. As shown in FIG. 4, at step 401, the producer can obtain a unique ticket from a ticketing system that is associated with the producer. Then, at step 402, the producer can go through a selected FIFO buffer sequencer. Furthermore, at step 403, the producer can store request in FIFO buffer at position identified by the ticket. This step can be highly concurrent, since multiple producers (e.g. up to the buffersize of producers) can proceed to store requests concurrently. Finally, at step 404, the producer may attempt to move a request from the FIFO buffer to the priority queue, e.g. by calling an add Loop( )function.

FIG. 5 shows an illustration of performing a dequeue operation 500 by a consumer in a computing environment, in accordance with an embodiment of the invention. As shown in FIG. 5, at step 501, the consumer can call a poll( )method and obtains a unique ticket from a ticketing system associated with the consumer. Then, at step 502, the consumer can go through the consumer sequencer. Furthermore, at step 503, the consumer can determine whether the priority queue is empty. For example, at step 504, the consumer can take one request from the priority queue, when the priority queue is not empty. Otherwise, at step 505, the consumer can take the first request from FIFO buffer when the priority queue is empty. This guarantees high throughput of the priority queue, since there may not be enough time to sort the requests. Finally, at step 506, the consumer may attempt to move a request from the FIFO buffer to the priority queue, e.g. by calling an add Loop( )function.

FIG. 6 shows an illustration of performing an operation 600 to move an element from a FIFO buffer to a priority queue, in accordance with an embodiment of the invention. As shown in FIG. 6, the operation to move an element from a FIFO buffer to a priority queue e.g. an addloop( ) method call, can be implemented using a loop.

At step 601, which is at the beginning of each iteration in the loop, the thread can check whether the FIFO buffers are empty. If the FIFO buffers are empty, at step 602, the system determines that the thread has nothing to do. Accordingly, at step 605, the thread returns and terminates the loop. On the other hand, at step 603, if the FIFO buffers are not empty, the thread can check whether there are consumers waiting, e.g. by checking the state of the consumer sequencer and the consumer ticketing system (i.e., if acquired consumer ticket>consumer sequencer current ticket).

At step 604, the system can determine that there are consumers waiting. Accordingly, at step 605, the thread returns and terminates the loop. This guarantees that producers step out of the way under high contention. In effect, the queue lock is biased towards consumers, which permits the complex structure of priority queue to be emptied quickly and permits the subsequent add operations to be performed quickly or to be completely eliminated.

Then, at step 606, the thread can claim one consumer ticket. This is made possible only if no consumers have arrived and are ready to perform dequeue operations. Furthermore, at step 607, the thread can move the first request from the FIFO buffer into the priority queue, which may have amortized logarithmic cost.

Finally, at step 608, the thread can advance the FIFO buffer sequencer, which allows the concurrent producers to reuse the emptied buffer cell, before finishing the iteration in the loop and proceeding to the next iteration by returning to step 601.

An Exemplary Implementation

FIG. 7 shows an illustration of an exemplary lazy sorting priority queue, in accordance with an embodiment of the invention. As shown in FIG. 7, the exemplary lazy sorting priority queue 700 can include a priority queue 701 and a FIFO buffer 702.

For example, the FIFO buffer 702 can be implemented using an array of Objects, q, and two sequencers, such as a readerS sequencer 722 and a writerS sequencer 721. Additionally, the priority queue 701 can be supported using a popperS sequencer 711.

As shown in FIG. 7, the producer 710 can place an element in the FIFO buffer 702 by atomically acquiring a ticket, adder_r 724, from the ticketing system, adder_tkt 723. Then, the producer 710 can wait on the writerS sequencer 721 for storing the element at a particular index in the array. Afterwards, the producer 710 can permit the progress of any thread attempting to read the same array cell by advancing the readerS sequencer 722. Furthermore, the producer 710 can attempt to move one or more elements to the priority queue 701.

Additionally, the consumer 720 can acquire a ticket, p_t 713, from the ticketing system, popper_tkt 712, e.g. using an atomic increment popper_tkt.getAndIncrement( )method call, and await on the popperS sequencer 711, e.g. via the popperS.await( )function call. Then, after removing an element from the priority queue 701 or the FIFO buffer 702, the consumer 720 may attempt to move one or more elements from the FIFO buffer 702 to the Priority Queue 701.

As shown in FIG. 7, both the producer 710 and the consumer 720 can call an addLoop( )method in order to move one or more elements from the FIFO queue 702 to the Priority Queue 701.

First, a thread, either the producer 710 or the consumer 720, can check whether the popperS sequencer 711 permits the thread to move one or more elements from the FIFO buffer 702 to the priority queue 701. For example, the thread can compare the value of the acquired ticket, p_t 713, with the value of the current ticket, popper_tkt 712.

Here, the popperS sequencer 711 may only allow a thread to move one or more elements from the FIFO buffer 702 to the priority queue 701, when there are no threads calling the poll( )method and the add Loop( )method. Additionally, the last thread that exits these methods can advance the popperS sequencer 711.

Otherwise, the thread, which corresponds to the current ticket, popper_tkt 712, is behind an existing thread in a poll( )method or an addLoop( )method. In such a case, there is no need to move elements from the FIFO buffer 702 to the priority queue 701, since doing so may either interfere with a consumer 720 extracting an element, or interfere with a thread that has already started moving elements from the FIFO buffer 702 to the priority queue 701.

Accordingly, the popperS sequencer 711 may not allow a thread to move one or more elements from the FIFO buffer 702 to the priority queue 701, when there is contention (i.e. when one or more consumers 720 are ready to extract units of work from the priority queue 701). Thus, the units of work in the FIFO buffer 702 can remain unsorted until a later thread, either a producer 710 or a consumer 720, finds a suitable time with no contention, or until the units of work are extracted by the consumers 720, if the contention remains high.

Furthermore, if popperS sequencer 711 permits progress for the current ticket, popper_tkt 712, the thread may attempt to atomically acquire this ticket, e.g. using a popper_tkt.compareAndSet(p_t, p_t+1) function call. This may succeed only if there is no thread attempting to acquire the same ticket in a concurrent call to poll( )or addLoop( )

On the other hand, when there are one or more concurrent threads, the system can guarantee that only one of the concurrent threads can successfully acquire the ticket. For example, this guarantee can be implemented via the atomic compareAndSet operation and the atomic getAndIncrement operation used by the addLoop( )method call and the poll( )ethod call, respectively. Thus, if the thread in a addLoop( )method call fails to acquire the ticket, there is no need to move elements, since, otherwise, the thread may either interfere with a consumer 720 extracting an element, or interfere with a thread that has already been moving elements from the FIFO buffer 702 to the priority queue 701.

In accordance with an embodiment of the invention, after successfully acquiring the ticket, the thread can execute a loop, in which the thread can move one unit of work at a time from the FIFO queue 702 to the priority queue 701. For example, since the thread can have exclusive access to the priority queue 701 (e.g. having progressed past popperS.await( )method call with a successfully acquired ticket), the thread can add the removed element to priority queue 701 using a priorityQueue.put( )method call.

Then, the thread can proceed to the next iteration of the loop. The loop continues until one or more consumers arrives at poll( )and waits to extract elements from the queue. The loop also terminates as soon as the FIFO buffer 702 becomes empty. After the loop terminates, the thread can advance the popperS sequencer 711 to permit the consumer 720 who has been waiting, or a future consumer 720, to proceed past popperS.await( )

Additionally, at the end of each iteration (or at the beginning of the next iteration), the thread can monitor the state of the ticketing system, popper_tkt 711, to detect a contender. The contender may only be a customer thread 720 in a poll( )method call, which can acquire a ticket unconditionally. Here, the thread entering the addLoop( )method call may detect that popperS sequencer 711 does not permit progress, and decide to exit without attempting to acquire a ticket.

For example, the detection of contention can be done by comparing the value of a successfully acquired ticket, p_t 713, with the value of a current ticket, popper_tkt 712. If popper_tkt >p_t, then the other thread must have incremented the current ticket, popper_tkt 711. Furthermore, the other thread can be waiting for proceeding past popperS.await( ) which is a blocking call to popperS sequencer 711 that force the other thread to wait until the ticket acquired by the thread is permitted to proceed. On the other hand, if popper_tkt==p_t, then no contenders have arrived, and the thread can move one unit of work fro FIFO queue 702 into priority queue 701 if FIFO queue 702 is not empty.

Here, in order to determine whether the FIFO queue 702 is empty, the thread can compare the acquired ticket, adder_r 724, with the current ticket, adder_tkt 723. If adder_tkt adder_r, then the FIFO queue must be empty. Otherwise, the FIFO queue 702 is not empty when adder_tkt>adder_r. Thus, the thread can move one element from the FIFO buffer 702 to the priority queue 701.

Furthermore, the thread can wait on the readerS sequencer 722, e.g. using a readerS.await(adder_r) method call. Then, the thread can proceed to work out the index of the array for the unit of work that is corresponding to the adder_r ticket 724. Additionally, the thread can advance the writers sequencer 721, e.g. using releaseWriters(adder_r), in order to permit concurrent producers 710 to use the array cell that was recently emptied.

The present invention may be conveniently implemented using one or more conventional general purpose or specialized digital computer, computing device, machine, or microprocessor, including one or more processors, memory and/or computer readable storage media programmed according to the teachings of the present disclosure. Appropriate software coding can readily be prepared by skilled programmers based on the teachings of the present disclosure, as will be apparent to those skilled in the software art.

In some embodiments, the present invention includes a computer program product which is a storage medium or computer readable medium (media) having instructions stored thereon/in which can be used to program a computer to perform any of the processes of the present invention. The storage medium can include, but is not limited to, any type of disk including floppy disks, optical discs, DVD, CD-ROMs, microdrive, and magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic or optical cards, nanosystems (including molecular memory ICs), or any type of media or device suitable for storing instructions and/or data.

The foregoing description of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. The modification and variation include any relevant combination of the described features. The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention for various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalence. 

What is claimed is:
 1. A system for supporting queue processing in a computing environment, comprising: a priority queue, wherein the priority queue operates to prioritize one or more incoming requests; and one or more buffers, wherein each said buffer operates to store one or more requests received from one or more producers, and move at least one message to the priority queue when no consumer is waiting for processing a request.
 2. The system according to claim 1, wherein: each said buffer allows one or more consumers to process said one or more requests in a first-in first-out (FIFO) order.
 3. The system according to claim 1, wherein: a producer operates to obtain a unique ticket from a ticket system associate with the producer, go through a buffer sequencer that is associated with a buffer selected from said one or more buffers, and store a request in the selected buffer at a position identified by the ticket.
 4. The system according to claim 4, wherein: a plurality of producers operate to store multiple requests in the selected buffer concurrently.
 5. The system according to claim 1, wherein: a consumer operates to obtain a unique ticket from a ticket system associate with the consumer, go through a consumer sequencer, and take a request from at least one of the priority queue and said one or more buffers.
 6. The system according to claim 5, wherein: the consumer operates to retrieve a request from the priority queue if the priority queue is not empty, or retrieve a first request from said one or more buffers if the priority queue is empty.
 7. The system according to claim 1, wherein: a thread that is associated with a producer or a consumer operates to check both the consumer sequencer and the ticketing system associated with the consumer.
 8. The system according to claim 7, wherein: the thread operates to return when there is at least one consumer waiting for processing a request.
 9. The system according to claim 1, wherein: the priority queue is maintained short to allow for lower complexity in performing an enqueing operation at the priority queue.
 10. The system according to claim 9, wherein: the priority queue becomes empty when consumers are at high contention level, and one or more requests are processed in the FIFO order.
 11. A method for supporting queue processing in a computing environment, the method comprising: providing a priority queue, wherein the priority queue operates to prioritize one or more incoming requests; providing one or more buffers, wherein each said buffer operates to store one or more requests received from one or more producers; and moving at least one message from said one or more buffers to the priority queue when no consumer is waiting for processing a request.
 12. The method of claim 11, further comprising: allowing one or more consumers to process said one or more requests in a first-in first-out (FIFO) order.
 13. The method according to claim 11, further comprising: obtaining, via a producer, a unique ticket from a ticket system associate with the producer, going through a buffer sequencer that is associated with a buffer selected from said one or more buffers, and storing a request in the selected buffer at a position identified by the ticket.
 14. The method according to claim 14, further comprising: allowing a plurality of producers to store multiple requests in the selected buffer concurrently.
 15. The method according to claim 11, further comprising: obtaining, via a consumer, a unique ticket from a ticket system associate with the consumer, going through a consumer sequencer, and taking a request from at least one of the priority queue and said one or more buffers.
 16. The method according to claim 15, further comprising: retrieving a request from the priority queue if the priority queue is not empty, or retrieving a first request from said one or more buffers if the priority queue is empty.
 17. The method according to claim 11, further comprising: allowing a thread that is associated with a producer or a consumer to check both the consumer sequencer and the ticketing system associated with the consumer.
 18. The method according to claim 17, further comprising: allowing the thread to return when there is at least one consumer waiting for processing a request.
 19. The method according to claim 11, further comprising: allowing the priority queue to be maintained short to allow for lower complexity in performing an enqueing operation at the priority queue, and allowing the priority queue to become empty when consumers are at high contention level, and one or more requests are processed in the FIFO order.
 20. A non-transitory machine readable storage medium having instructions stored thereon that when executed cause a system to perform the steps comprising: providing a priority queue, wherein the priority queue operates to prioritize one or more incoming requests; providing one or more buffers, wherein each said buffer operates to store one or more requests received from one or more producers; and moving at least one message from said one or more buffers to the priority queue when no consumer is waiting for processing a request. 